package com.wn.www.carbeauty.controller;

import com.wn.www.carbeauty.entity.dto.OrderDto;
import com.wn.www.carbeauty.entity.dto.PayDto;
import com.wn.www.carbeauty.service.IOrdersService;
import com.wn.www.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chan
 * @since 2025-04-11
 */
@RestController
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    private IOrdersService ordersService;

    @PostMapping("/create")
    public Result createOrderAndPay(@RequestBody OrderDto orderDto){
        return Result.ok(ordersService.createOrderAndPay(orderDto));
    }

    @PostMapping("/pay")
    public String paySuccess(@RequestBody PayDto payDto){
        ordersService.paySuccess(payDto.getId());
        return "success";
    }

    @PostMapping("/confirmed")
    public Result payConfirmed(@RequestBody PayDto payDto){
        ordersService.payConfirmed(payDto.getId());
        return Result.ok();
    }

}
